package dryven.codegen.asm.typeinfo;


public abstract class AbstractTypeInfo implements TypeInfo {

	public AbstractTypeInfo() {
		super();
	}
	

	@Override
	public boolean isRepresentedByInt() {
		return isBoolean() || isChar() || isByte() || isShort() || isInt();
	}

	public int getPrimitiveCastScale() {
		if(isBoolean()) {
			return 1;
		}
		if(isChar()) {
			return 2;
		}
		if(isByte()) {
			return 3;
		}
		if(isShort()) {
			return 4;
		}
		if(isInt()) {
			return 5;
		}
		if(isLong()) {
			return 6;
		}
		if(isFloat()) {
			return 7;
		}
		if(isDouble()) {
			return 8;
		}
		return -1;
	}

	public TypeInfo castPrimitiveUp(TypeInfo t) {
		int aCastScale = getPrimitiveCastScale();
		int bCastScale = t.getPrimitiveCastScale();
		if(aCastScale!=-1 && bCastScale!=-1) {
			return (aCastScale>bCastScale?this:t);
		}
		return null;
	}


	@Override
	public int getSlotSize() {
		return (isLong() || isDouble())?2:1;
	}

}